﻿using System.Text.RegularExpressions;

namespace TodoApi.Parameter
{
    public class SelectParameter
    {
        /// <summary>
        /// 搜索名字
        /// </summary>
        public string? Search { get; set; }
        /// <summary>
        /// 是否排序
        /// </summary>
        public bool Sort { get; set; }
        /// <summary>
        /// 起始
        /// </summary>
        public int Start { get; set; }
        /// <summary>
        /// 个数
        /// </summary>
        public int Length { get; set; }
        public int? MinAge { get; set; }
        public int? MaxAge { get; set; }
        private  string _age;
        /// <summary>
        /// 年龄段   1-18
        /// </summary>
        public string? Age { get { return _age; } 
            set {
                if (!string.IsNullOrEmpty(value))
                {
                    Regex regex = new Regex(@"^\d*-\d*$");
                    if (regex.Match(value).Success)
                    {
                        MinAge = Int32.Parse(value.Split("-")[0]);
                        MaxAge = Int32.Parse(value.Split("-")[1]);
                    }
                }
                _age = value;

            } 
        }
    }
}
